package cn.itcast.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {


    /**
     * 声明队列（不存在会创建）
     * @return
     */
    @Bean
    public Queue simpleQueue(){
        return new Queue("simple.queue",true);
    }


    /**
     * 声明队列（不存在会创建）
     * @return
     */
    @Bean
    public Queue workQueue(){
        return new Queue("work.queue",true);
    }


    @Bean
    public Queue fanoutQueue1(){
        return new Queue("fanout.queue1",true);
    }

    @Bean
    public Queue fanoutQueue2(){
        return new Queue("fanout.queue2",true);
    }


    @Bean
    public FanoutExchange fanoutExchange(){
        return new FanoutExchange("fanout.exchange");
    }

    /**
     * 声明广播交换机和队列的绑定关系
     * @param fanoutQueue1
     * @param fanoutExchange
     * @return
     */
    @Bean
    public Binding bindFanoutQueue1(Queue fanoutQueue1, FanoutExchange fanoutExchange){
        return BindingBuilder.bind(fanoutQueue1).to(fanoutExchange);
    }


    @Bean
    public Binding bindFanoutQueue2(){
        return BindingBuilder.bind(fanoutQueue2()).to(fanoutExchange());
    }

    @Bean
    public Queue objectQueue(){
        return new Queue("object.queue",true);
    }
}

